/*
 * @lc app=leetcode.cn id=33 lang=javascript
 *
 * [33] 搜索旋转排序数组
 */

// @lc code=start
/**
 * @param {number[]} nums
 * @param {number} target
 * @return {number}
 */
var search = function(nums, target) {
    let l=0,r=nums.length-1
    while(l<r){
        let mid=(l+r)>>1
        if(nums[0]>nums[mid]){
            r=mid
        }else{
            l=mid+1
        }
    }
    if(nums[0]>target){
        r=nums.length-1
    }else{
        l=0
    }
    while(l<=r){
        mid=(l+r)>>1
        if(nums[mid]==target){return mid}
        else if(nums[mid]>target){
            r=mid-1
        }else{
            l=mid+1
        }
    }
    return -1
};
// @lc code=end

